package com.kitty.listener.event;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.game.role.model.Role;
import com.kitty.listener.BasePlayerEvent;
import com.kitty.listener.EventType;
import lombok.Getter;
import org.nutz.lang.util.NutMap;

import java.util.ArrayList;
import java.util.List;

/**战斗结束*/
@Getter
public class FightEndEvent extends BasePlayerEvent {
    /**战斗胜利*/
    public static final byte WIN = 1;
    /**战斗失败*/
    public static final byte FAIL = 2;
    /**战斗逃跑*/
    public static final byte RUNAWAY = 3;
    /**战斗超过最大回合*/
    public static final byte MAXROUND = 40;

    private Role role;
    /**战斗ID，对应哪个战斗*/
    private int fightId;
    /**战斗结束状态*/
    private byte status;
    private int fightType;
    /**战斗胜利奖励*/
    private NutMap reward;
    /**对应任务ID*/
    private int taskId;
    /**对应的NPC Id*/
    private int npcId;
    /**当前参战的宠物ID*/
    private int currPetId;
    private List<Role> rolesA;
    private List<Role> rolesB;




    public FightEndEvent(Fight fight, EventType evtType, Role role, int fightId, byte status, int fightType, NutMap reward, int taskId, int npcId , int currPetId) {
        super(evtType, role);
        this.role = role;
        this.fightId = fightId;
        this.status = status;
        this.fightType = fightType;
        this.reward = reward;
        this.taskId = taskId;
        this.npcId = npcId;
        this.currPetId =currPetId;
        this.rolesA = getRoles(fight.getListA());
        this.rolesB = getRoles(fight.getListB());
    }

    private List<Role> getRoles(List<FightObject> list) {
        List<Role> roles = new ArrayList<>();
        for (FightObject fightObject : list) {
            if (fightObject.isPlayer()) {
                roles.add(fightObject.getRole());
            }
        }
        return roles;
    }
}
